var LOADER = function (that, options) {
  this.options = options
  this.self = that
}
LOADER.VERSION = 'v0.0.5_Alpha '
LOADER.DEFAULTS = {
  size: 25,
  borderWidth:1,
  text: "", //载入提示文字
  textColor: '',
  layout: "", //line
  toast: true,
  isInit: false,
  open:false,
  animation:true
}
LOADER.prototype.init = function () {
  if (!this.isInit) {
    var options = this.options
    this.self.setData({
      [this.options.data || "nv_loader"]: options
    });
    this.isInit = true
  }
}
LOADER.prototype.open = function (options) {
  var _options=this.options
  _options.open = true
  _options.animation = true
  if (typeof options == undefined || !options){
    _options.text = ""
  } else if (typeof options == 'object'){
    _options = extend(_options, options)
  } else if (typeof options == 'string' && options) {
    _options.animation = false
    _options.text = options
  }
  this.self.setData({
    [_options.data || "loader"]: _options
  });
}
LOADER.prototype.close = function () {
  var _options = this.options
  _options.open = false
  this.self.setData({
    [_options.data || "loader"]: _options
  });
}
function extend(jsonbject1, jsonbject2) {
  var resultJsonObject = {}
  for (var attr in jsonbject1) {
    resultJsonObject[attr] = jsonbject1[attr];
  }
  for (var attr in jsonbject2) {
    resultJsonObject[attr] = jsonbject2[attr];
  }
  return resultJsonObject
}
function init(that, option) {
  var options = extend(LOADER.DEFAULTS, option)
  var data = new LOADER(that, options)
  data.init()
  return data
}
module.exports = {
  loader: init
}